const { resolve } = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')

const config = {
  entry: ['./src/index.tsx'],

  output: {
    filename: 'assets/bundle.js',
    chunkFilename: 'assets/[name].js',
    path: resolve(__dirname, '../build'),
  },

  resolve: {
    extensions: ['.tsx', '.ts', '.js', '.json'],
    alias: {
      '@': resolve(__dirname, '../src'),
    },
  },

  module: {
    rules: [
      {
        test: /\.(j|t)sx?$/,
        exclude: /node_modules/,
        loader: 'babel-loader',
        options: {
          // disable type checker - we will use it in fork plugin
          cacheDirectory: true,
        },
      },
    ],
  },

  plugins: [
    // new WebpackBar(),

    new ForkTsCheckerWebpackPlugin(),

    new HtmlWebpackPlugin({
      inject: true,
      template: resolve(__dirname, '../public/index.html'),
    }),
  ],
}

module.exports = config
